﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using EFong.ServicesInterface;
using System.ServiceModel.Channels;
using UIShare;
using EFong.Contract;

namespace EFong.View.Proxy
{
    public class ReportServiceProxy : ClientBase<IReportService>, IReportService
    {
        #region Constructor

        public ReportServiceProxy(string endpointConfigurationName) : 
            base(endpointConfigurationName)
        { 
        }

        public ReportServiceProxy(InstanceContext callbackInstance) :
            base(callbackInstance)
        {
        }

        public ReportServiceProxy(InstanceContext callbackInstance, string endpointConfigurationName) :
            base(callbackInstance, endpointConfigurationName)
        {
        }

        public ReportServiceProxy(InstanceContext callbackInstance, string endpointConfigurationName, string remoteAddress) :
            base(callbackInstance, endpointConfigurationName, remoteAddress)
        {
        }

        public ReportServiceProxy(InstanceContext callbackInstance, string endpointConfigurationName, EndpointAddress remoteAddress) :
            base(callbackInstance, endpointConfigurationName, remoteAddress)
        {
        }

        public ReportServiceProxy(InstanceContext callbackInstance, Binding binding, EndpointAddress remoteAddress) :
            base(callbackInstance, binding, remoteAddress)
        {
        }

        public ReportServiceProxy(Binding binding, EndpointAddress remoteAddress) :
            base( binding, remoteAddress)
        {
        }

        private static ReportServiceProxy _instance;
        public static ReportServiceProxy GetInstance() 
        {
            if (_instance == null || _instance.State == CommunicationState.Faulted)
            {
                string url = string.Format("Http://{0}:{1}/{2}", ProxyMgt.IP, ProxyMgt.Port, "ReportService");

                EndpointAddress epa = new EndpointAddress(url);

                WSHttpBinding binding = new WSHttpBinding();
                //binding.ReliableSession.Enabled = true;
                binding.Security.Mode = SecurityMode.None;
                binding.SendTimeout = new TimeSpan(0, 1, 30);
                binding.MaxReceivedMessageSize = 65536000;
                binding.ReaderQuotas.MaxStringContentLength = 65536000;

                _instance = new ReportServiceProxy(binding, epa);
            }
            return _instance;
        }

        #endregion

        #region IReportService 成员

        public Contract.ServiceResult<List<Contract.银行对账单>> GetReport01(Contract.BankAccount bankAccount, DateTime startDate, DateTime endDate)
        {
            var result = base.Channel.GetReport01(bankAccount, startDate,endDate);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.银行对账单>> GetReport011(DateTime startDate, DateTime endDate)
        {
            var result = base.Channel.GetReport011( startDate, endDate);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.供应商对账单>> GetReport02(RVendor vendor, DateTime month)
        {
            var result = base.Channel.GetReport02(vendor , month);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.固定费用清单>> GetReport03(DateTime month)
        {
            var result = base.Channel.GetReport03(month);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.零散费用清单>> GetReport04(DateTime month)
        {
            var result = base.Channel.GetReport04(month);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.利润表>> GetReport05(DateTime startDay, DateTime endDay)
        {
            var result = base.Channel.GetReport05(startDay,endDay);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.飞机票月结对账单>> GetReport06(RCustomer customer, DateTime startDate , DateTime endDate)
        {
            var result = base.Channel.GetReport06(customer, startDate,endDate);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.火车票月结对账单>> GetReport07(RCustomer customer, DateTime month)
        {
            var result = base.Channel.GetReport07(customer, month);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.酒店月结对账单>> GetReport08(RCustomer customer, DateTime month)
        {
            var result = base.Channel.GetReport08(customer, month);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.其他项目月结对账单>> GetReport09(RCustomer customer, DateTime month)
        {
            var result = base.Channel.GetReport09(customer,month);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.每日订单报表>> GetReport10(DateTime day)
        {
            var result = base.Channel.GetReport10(day);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.应付款报表>> GetReport11()
        {
            var result = base.Channel.GetReport11();
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.应收款报表>> GetReport12()
        {
            var result = base.Channel.GetReport12();
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.已收款报表>> GetReport13(RCustomer customer ,DateTime startDay,DateTime endDay)
        {
            var result = base.Channel.GetReport13(customer , startDay , endDay);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.已付款报表>> GetReport14(RVendor vendor, DateTime startDay, DateTime endDay)
        {
            var result = base.Channel.GetReport14(vendor,startDay, endDay);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<Contract.资金流动报表> GetReport15()
        {
            var result = base.Channel.GetReport15();
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.每日订单报表>> GetReport16(Contract.User orderUser, DateTime month)
        {
            var result = base.Channel.GetReport16(orderUser, month);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.每日订单报表>> GetReport17(Contract.User provideUser, DateTime month)
        {
            var result = base.Channel.GetReport17(provideUser, month);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        public Contract.ServiceResult<List<Contract.飞机总表>> GetReport18(DateTime startDate, DateTime endDate)
        {
            var result = base.Channel.GetReport18(startDate, endDate);
            if (!result.IsSuccess)
                MsgBox.Error(result.FailMessage);
            return result;
        }

        #endregion
    }
}
